﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aandelendelen.Obs;
using Aandelendelen.Mail;

namespace Aandelendelen.Controls
{
	public partial class BuyCreditsControl : AuthenticationRequiredBaseUserControl
	{
		protected override void OnPostBack(object sender, EventArgs e)
		{
			this.HandleBuy();
		}

		private void HandleBuy()
		{
			if (this.rbIdeal.Checked)
			{
				Response.Redirect("/IdealPayment.aspx", true);
			}

			Userinfo userInfo = this.UserInfo;

			string mailName = "";
			MailArguments mailArgs = MailArguments.MailArgs;
			mailArgs.Clear();

			mailArgs["{aanhef}"] = userInfo.MailAanhef;
			mailArgs["{uid}"] = userInfo.Gebruikersnaam;

			if (this.rbBank.Checked)
				mailName = "buycreditsbank";

			EMail email = MailCache.GetMail(mailName);
			email.Recipients = userInfo.Email;

			email.QueueSingle();

			this.lblConfirm.Visible = true;
			this.pnlText.Visible = false;
		}
	}
}